#include "gps2u.h"
#include "stc8h.h"
#include "INTRINS.H"
#include "fun.h"
#include "STRING.H"
#include "UC1701X.h"
char xdata buf2[256] ;
bit sw=0;
unsigned char wp=0;
unsigned char n=0;
bit cf_=0;



void Uart2_Isr(void) interrupt 8
{
	if (S2CON & 0x02)	//检测串口2发送中断
	{
		S2CON &= ~0x02;	//清除串口2发送中断请求位
	}
	if (S2CON & 0x01)	//检测串口2接收中断
	{
		S2CON &= ~0x01;	//清除串口2接收中断请求位
        if(S2BUF == 0x0a){
            sw=~sw;
            wp=sw;
            wp=(wp<<7);
            cf_=1;
        }else{
            buf2[wp++]=S2BUF;
        }
        
	}
}

void Uart2_Init(void)	//9600bps@11.0592MHz
{
    P_SW2 |= UART2_PORT;						//UART2/USART2: RxD2(P4.6), TxD2(P4.7)
	S2CON = 0x50;		//8位数据,可变波特率
	AUXR |= 0x04;		//定时器时钟1T模式
	T2L = 0xE0;			//设置定时初始值
	T2H = 0xFE;			//设置定时初始值
	AUXR |= 0x10;		//定时器2开始计时
	IE2 |= 0x01;		//使能串口2中断
}
void sh(void){
    char b[16]={0};
    unsigned char i=0;
    unsigned char p=0;
    unsigned char rp;
    char k=0;
    if(cf_==1){
        cf_=0;
        rp=~wp;
        rp&=0x80;
        if(buf2[rp+5]!=0x43){
            // return 0;
            // UartSend(buf2[rp+5]);
            buf2[rp+1]=0x0d;
        };  

        while(buf2[rp]!=0x0d){
            // UartSend(buf2[rp++]);
            b[i]=buf2[rp++];
            if(b[i] == 0x2c){
                i=0;
                p++;
            }else{
                i++;
            }
            if(i==0){
                if((p&0x01)==0){
                    lcd_address(k++,0);
                    k&=0x07;
                }
                lcd_print8(b);
                UartSendStr(b);
                memset(b,0,16);
            }

        }
        
    }
    
}


